using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(C2DCamera))]
public class C2DCameraEditor : Editor 
{
	C2DCamera m_c2dCamera;
	
	public void OnEnable()
	{
		m_c2dCamera = (C2DCamera)(target);
	} 
	
	public static Vector2 GetMainGameViewSize()
	{
		System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
		System.Reflection.MethodInfo GetSizeOfMainGameView = T.GetMethod("GetSizeOfMainGameView",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
		System.Object Res = GetSizeOfMainGameView.Invoke(null,null);
		return (Vector2)Res;
	}
	
	public override void OnInspectorGUI() 
	{
    	m_c2dCamera.m_uNativeResolutionX = (int)EditorGUILayout.IntField( "Native Resolution X", (int)m_c2dCamera.m_uNativeResolutionX);
		
    	m_c2dCamera.m_uNativeResolutionY = (int)EditorGUILayout.IntField( "Native Resolution y",(int)m_c2dCamera.m_uNativeResolutionY);
		
    	m_c2dCamera.m_bPixelPerfect = EditorGUILayout.Toggle( "Pixel Perfect", m_c2dCamera.m_bPixelPerfect );
	
		if( GUI.changed )
		{
			Vector2 ViewSize = GetMainGameViewSize();
			
			m_c2dCamera.Calculate( ViewSize );
			
			SceneView.RepaintAll();
		}
		
		//this.Repaint();
	}	
	
	//public override void On
}
